TicTacToe đơn giản trong JavaScript với mã nguồn
5.429 lượt xem;
1 // Player as Class
2 var countdown;
3 class Player {
4 // Special constructor method
5 constructor(name, score, turnTotal, avatar, spot) {
6 // Set properties
7 this.name = name;
8 this.score = score;
9 this.turnTotal = turnTotal;
10 this.avatar = avatar;
11 this.spot = spot;
12
13 }
14 }
15
16 class Tiles {
17 constructor(id, width, height, x, y, snake, ladder, next) {
18 this.id = id;
19 this.width = width;
20 this.height = height;
21 this.x = x;
22 this.y = y;
23 this.snake = snake;
24 this.ladder = ladder;
25 this.next = next;
26 }
27
28 }
29
30
31 class Blocks {
32 constructor(id, className, innerText, bgColor, snake, ladder, next) {
33 this.id = id;
34 this.className = className;
35 this.innerText = innerText;
36 this.bgColor = bgColor;
37 this.snake = snake;
38 this.ladder = ladder;
39 this.next = next;
40 }
41
42 }
43
44
45
46 class MemoryBlock {
47 constructor(id, frontImage, backImage) {
48 this.id = id;
49 this.blockCSS = "block";
50 this.frontImage = frontImage;
51 this.backImage = backImage;
52 this.front = false;
53 this.back = true;
54 this.frontCSS = "block-front block-face";
55 this.backCSS = "block-back block-face";
56 this.imgCSS = "block-value";
57
58 }
59 }
60
61 function startTimer(duration, display) {
62 var timer = 60 * duration, minutes, seconds;
63 countdown = setInterval(() => {
64 minutes = parseInt(timer / 60, 10);
65 seconds = parseInt(timer % 60, 10);
66 minutes = minutes < 10 ? "0" + minutes : minutes;
67 seconds = seconds < 10 ? "0" + seconds : seconds;
68 display.textContent = `Time ${ minutes }:${ seconds }`;
69 if (--timer < 0) {
70 gameOver();
71 }
72 }, 1000);
73 }
74
75 class gameInfo {
76 constructor(totalTime, cards) {
77 this.cardsArray = cards;
78 this.totalTime = totalTime;
79 this.timeRemaining = totalTime;
80 // this.timer = document.getElementById('time-remaining');
81 this.flips = 0;
82 }
83 }
2 var countdown;
3 class Player {
4 // Special constructor method
5 constructor(name, score, turnTotal, avatar, spot) {
6 // Set properties
7 this.name = name;
8 this.score = score;
9 this.turnTotal = turnTotal;
10 this.avatar = avatar;
11 this.spot = spot;
12
13 }
14 }
15
16 class Tiles {
17 constructor(id, width, height, x, y, snake, ladder, next) {
18 this.id = id;
19 this.width = width;
20 this.height = height;
21 this.x = x;
22 this.y = y;
23 this.snake = snake;
24 this.ladder = ladder;
25 this.next = next;
26 }
27
28 }
29
30
31 class Blocks {
32 constructor(id, className, innerText, bgColor, snake, ladder, next) {
33 this.id = id;
34 this.className = className;
35 this.innerText = innerText;
36 this.bgColor = bgColor;
37 this.snake = snake;
38 this.ladder = ladder;
39 this.next = next;
40 }
41
42 }
43
44
45
46 class MemoryBlock {
47 constructor(id, frontImage, backImage) {
48 this.id = id;
49 this.blockCSS = "block";
50 this.frontImage = frontImage;
51 this.backImage = backImage;
52 this.front = false;
53 this.back = true;
54 this.frontCSS = "block-front block-face";
55 this.backCSS = "block-back block-face";
56 this.imgCSS = "block-value";
57
58 }
59 }
60
61 function startTimer(duration, display) {
62 var timer = 60 * duration, minutes, seconds;
63 countdown = setInterval(() => {
64 minutes = parseInt(timer / 60, 10);
65 seconds = parseInt(timer % 60, 10);
66 minutes = minutes < 10 ? "0" + minutes : minutes;
67 seconds = seconds < 10 ? "0" + seconds : seconds;
68 display.textContent = `Time ${ minutes }:${ seconds }`;
69 if (--timer < 0) {
70 gameOver();
71 }
72 }, 1000);
73 }
74
75 class gameInfo {
76 constructor(totalTime, cards) {
77 this.cardsArray = cards;
78 this.totalTime = totalTime;
79 this.timeRemaining = totalTime;
80 // this.timer = document.getElementById('time-remaining');
81 this.flips = 0;
82 }
83 }